package cn.bravolinks.tools.controller;

import cn.bravolinks.tools.constant.Constant;
import cn.bravolinks.tools.domain.Task;
import cn.bravolinks.tools.domain.User;
import cn.bravolinks.tools.service.TaskService;
import cn.bravolinks.tools.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yanqin on 2017/6/4.
 */
@Controller
@RequestMapping("user")
public class UserController extends BaseController{

    @Autowired
    private TaskService taskService;
    @Autowired
    private UserService userService;
    @RequestMapping("/")
    public String userPage(String menuType){
        User u = (User) session.getAttribute(Constant.LOGIN_USER);
        request.setAttribute("user",u);
        request.setAttribute("menuType",menuType);
    	System.out.println(menuType);
        //查询该用户的任务
        List<Task> tasks = taskService.get(u.getId(),null,null);
        request.setAttribute("tasks",tasks);
        List<User> resultUserList = userService.queryUser();
        request.setAttribute("resultUserList",resultUserList);
        return "UserManagement";
    }
    @RequestMapping("/queryUser")
    public String queryUser(String menuType){
        List<User> resultUserList = userService.queryUser();
        request.setAttribute("resultUserList",resultUserList);
        request.setAttribute("menuType",menuType);
        return "UserManagement";
    }
}
